# ==============================
# _*_ coding:utf-8 _*_
# _*_ by:zizle     _*_
# _*_ at:20230423  _*_
# ==============================

from utils.ths_api import THSApi
from db_utils import BaseDatabaseConnection

ths = THSApi()
data = ths.get_candle_daily(codes=['000001.SH', '399001.SZ'], indicators=['open','close','low', 'high'],
                            start_date='2023-04-21', end_date='2023-04-21')
# print(data)
for c in data:
    print(c)
    print(data[c])

    with BaseDatabaseConnection() as conn:
        count = conn.cursor.executemany("""
            insert into quote_candle_daily(`time`,`code`,`open`,`close`,`low`,`high`) 
            VALUES (%(time)s,%(code)s,%(open)s,%(close)s,%(low)s,%(high)s);
        """, data[c])
        print('保存{}完成，数量:{}'.format(c, count))